home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 16.4 KB | 566 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: BmpFrame.cpp
- // Release Version: $ 1.0d11 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFBMap.hpp"
-
- #ifndef BMPFRAME_H
- #include "BmpFrame.h"
- #endif
-
- #ifndef BMPPART_H
- #include "BmpPart.h"
- #endif
-
- #ifndef BMPSEL_H
- #include "BmpSel.h"
- #endif
-
- #ifndef RBBRBAND_H
- #include "RbbrBand.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRTITE_H
- #include "FWPrtIte.h"
- #endif
-
- #ifndef FWGROWBX_H
- #include "FWGrowBx.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWBMPSHP_H
- #include "FWBmpShp.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfbitmap
- #endif
-
- //========================================================================================
- // class CBitmapFrame
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::CBitmapFrame
- //----------------------------------------------------------------------------------------
- // CBitmapFrame constructor
-
- CBitmapFrame::CBitmapFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CBitmapPart* bitmapPart) :
- FW_CFrame(ev, odFrame, presentation, bitmapPart),
- fBitmapPart(bitmapPart),
- fChoosenSize(cRealSize),
- fGrowBox(NULL),
- fSelection((CBitmapSelection*)presentation->GetSelection(ev))
- {
- // ----- Save my current frame rect -----
- fFrameRect = this->GetBounds(ev);
-
- // ----- I want to be droppable -----
- this->SetDroppable(ev, TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::~CBitmapFrame
- //----------------------------------------------------------------------------------------
- // CBitmapFrame destructor
-
- CBitmapFrame::~CBitmapFrame()
- {
- // ----- Nothing to do -----
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::DoAdjustMenus
- //----------------------------------------------------------------------------------------
- // ODF Method
-
- FW_Boolean CBitmapFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot)
- {
- if (hasMenuFocus)
- {
- // ----- OpenDoc Items -----
- FW_Boolean hasRightProperty = HasPropertyOnClipboard(ev, kODPropContents, CBitmapPart::kPartKind);
-
- #ifdef FW_BUILD_MAC
- // ----- On the Mac I allow Paste for both my kind and PICT. On Window I only allow Paste for my kind
- if (!hasRightProperty)
- hasRightProperty = hasRightProperty || HasPropertyOnClipboard(ev, kODPropContents, FW_CPart::gMacPICTDataType);
- #endif
-
- menuBar->EnableCommand(ev, kODCommandSelectAll, TRUE); // Allow Select All
- menuBar->EnableCommand(ev, kODCommandClear, FALSE); // Don't allow Clear
- menuBar->EnableCommand(ev, kODCommandCut, FALSE); // Don't allow cut
- menuBar->EnableCommand(ev, kODCommandCopy, !fSelection->IsEmpty(ev)); // Allow copy only if my selection is not empty
- menuBar->EnableCommand(ev, kODCommandPaste, hasRightProperty); // Allow Paste if right property on the clipboard
- menuBar->EnableCommand(ev, kODCommandPasteAs, FALSE); // Don't allow Past As for now
-
- // ----- My Items -----
- ODCommandID choosenSize = GetChoosenSize();
-
- menuBar->EnableAndCheckCommand(ev, cHalfSize, TRUE, fChoosenSize == cHalfSize);
- menuBar->EnableAndCheckCommand(ev, cRealSize, TRUE, fChoosenSize == cRealSize);
- menuBar->EnableAndCheckCommand(ev, cDoubleSize, TRUE, fChoosenSize == cDoubleSize);
- menuBar->EnableAndCheckCommand(ev, cFitToFrame, TRUE, fChoosenSize == cFitToFrame);
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::DoMenu
- //----------------------------------------------------------------------------------------
- // ODF method
-
- FW_Boolean CBitmapFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
- {
- FW_Boolean result = TRUE;
- ODCommandID commandID = theMenuEvent.GetCommandID(ev);
-
- if (commandID == cHalfSize ||
- commandID == cRealSize ||
- commandID == cDoubleSize ||
- commandID == cFitToFrame)
- {
- if (commandID != fChoosenSize)
- {
- fChoosenSize = commandID;
- fBitmapPart->AdjustFramesSize(ev);
- }
- }
- else
- result = FALSE;
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::DoIdle
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CBitmapFrame::DoIdle(Environment* ev, const FW_CNullEvent& theNullEvent)
- {
- FW_UNUSED(theNullEvent);
- if (fSelection != NULL && !fSelection->IsEmpty(ev))
- fSelection->MoveAnts(ev, this);
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::AdjustFrameSize
- //----------------------------------------------------------------------------------------
-
- void CBitmapFrame::AdjustFrameSize(Environment* ev)
- {
- if (IsRoot(ev))
- UpdateUsedAndActiveShapes(ev);
- else
- {
- FW_CRect usedRect;
- CalcUsedRect(ev, usedRect);
- usedRect.Place(FW_kZeroPoint);
-
- FW_CAcquiredODShape aqAskedFrameShape = ::FW_NewODShape(ev, usedRect);
- FW_CAcquiredODShape aqFrameShape = AcquireFrameShape(ev);
-
- if (aqAskedFrameShape->IsSameAs(ev, aqFrameShape))
- UpdateUsedAndActiveShapes(ev);
- else
- this->RequestFrameShape(ev, aqAskedFrameShape);
- }
-
- this->Invalidate(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::FocusStateChanged
- //----------------------------------------------------------------------------------------
-
- void CBitmapFrame::FocusStateChanged(Environment* ev, ODTypeToken focus, FW_Boolean newState, ODFrame* newOwner)
- {
- FW_CFrame::FocusStateChanged(ev, focus, newState, newOwner);
-
- if (focus == FW_CPart::gSelectionFocusToken)
- {
- if (!fSelection->IsEmpty(ev))
- fSelection->DrawAnts(ev, this);
-
- if (newState)
- RegisterIdle(ev, 15);
- else
- UnregisterIdle(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::FrameShapeChanged
- //----------------------------------------------------------------------------------------
-
- void CBitmapFrame::FrameShapeChanged(Environment* ev)
- {
- FW_CFrame::FrameShapeChanged(ev);
-
- FW_CRect updateRect(fFrameRect);
-
- fFrameRect = GetBounds(ev); // Get new Frame Rect
-
- updateRect.Union(fFrameRect);
-
- // ----- Force redraw of the frame shape -----
- this->Invalidate(ev, updateRect);
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::BuildThumbnail
- //----------------------------------------------------------------------------------------
-
- void CBitmapFrame::BuildThumbnail(Environment* ev, FW_CGraphicContext& gc, const FW_CRect& bounds)
- {
- FW_PBitmap bitmap = fBitmapPart->GetBitmap(ev);
-
- FW_CRect dstRect;
- bitmap->GetBitmapBounds(gc, dstRect);
- dstRect.Place(FW_kZeroPoint);
-
- FW_CRect rect(bounds);
- rect.Place(FW_kZeroPoint);
- if (rect.right / dstRect.right < rect.bottom / dstRect.bottom)
- {
- dstRect.right = rect.right;
- dstRect.bottom = (dstRect.bottom / dstRect.right) * rect.right;
- }
- else
- {
- dstRect.right = (dstRect.bottom / dstRect.right) * rect.bottom;
- dstRect.bottom = rect.bottom;
- }
-
- dstRect.PlaceInCenter(bounds);
-
- FW_CBitmapShape::RenderBitmap(gc, bitmap, dstRect);
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::AdjustUsedShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CBitmapFrame::AdjustUsedShape(Environment* ev, ODShape* suggestedUsedShape)
- {
- FW_CRect usedShapeRect;
- CalcUsedRect(ev, usedShapeRect);
-
- FW_CRect frameRect = GetBounds(ev);
- usedShapeRect.Intersection(frameRect);
-
- ODRect odUsedShapeRect = usedShapeRect;
- suggestedUsedShape->SetRectangle(ev, &odUsedShapeRect);
-
- suggestedUsedShape->Acquire(ev); // because I am reusing the shape passed as parameter
- return suggestedUsedShape;
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::AdjustActiveShape
- //----------------------------------------------------------------------------------------
- // [HLX] Because OpenDoc uses the Frame shape as the default active shape I need to
- // adjust my active shape too.
-
- ODShape* CBitmapFrame::AdjustActiveShape(Environment* ev, ODFacet* facet, ODShape* suggestedActiveShape)
- {
- suggestedActiveShape->Acquire(ev);
- return suggestedActiveShape;
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::AdjustZoomedWindowSize
- //----------------------------------------------------------------------------------------
-
- void CBitmapFrame::AdjustZoomedWindowSize(Environment *ev, FW_CPoint& proposedSize)
- {
- FW_CRect usedShapeRect;
- CalcUsedRect(ev, usedShapeRect);
-
- proposedSize.Set(usedShapeRect.Width() + FW_IntToFixed(10), usedShapeRect.Height() + FW_IntToFixed(10));
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::GetZoomRatio
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CBitmapFrame::GetZoomRatio(Environment* ev) const
- {
- FW_PBitmap bitmap = fBitmapPart->GetBitmap(ev);
- FW_CRect bounds;
- bitmap->GetBitmapBounds(bounds);
-
- FW_CRect usedRect;
- CalcUsedRect(ev, usedRect);
-
- FW_CPoint ratio(
- (usedRect.right - usedRect.left) / bounds.right,
- (usedRect.bottom - usedRect.top) / bounds.bottom);
-
- return ratio;
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::Draw
- //----------------------------------------------------------------------------------------
-
- void CBitmapFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- FW_CViewContext vc(ev, this, odFacet, invalidShape);
-
- // ------ [HLX] Will be moved to an adorner
- if (IsTopFrame(ev))
- {
- FW_CRect invalidRect;
- vc.GetClipRect(invalidRect);
-
- #ifdef FW_BUILD_MAC
- FW_PInk ink(FW_kRGBWhite,
- FW_kRGBWhite,
- FW_kErase);
- #else
- FW_PInk ink(FW_CColor(::GetSysColor(COLOR_WINDOWTEXT), 0),
- FW_CColor(::GetSysColor(COLOR_APPWORKSPACE), 0),
- FW_kErase);
- #endif
- FW_CRectShape::RenderRect(vc, invalidRect, FW_kFill, ink);
- }
-
- FW_CRect usedRect;
- CalcUsedRect(ev, usedRect);
-
- // ----- Use the static rendering method -----
- FW_CBitmapShape::RenderBitmap(vc, fBitmapPart->GetBitmap(ev), usedRect);
-
- // ----- Draw the ants if there is a selection -----
- if (IsActive(ev) && !fSelection->IsEmpty(ev))
- {
- fSelection->DoDrawAnts(ev, vc, this);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::CalcUsedRect
- //----------------------------------------------------------------------------------------
-
- void CBitmapFrame::CalcUsedRect(Environment* ev, FW_CRect& newUsedRect) const
- {
- ODCommandID choosenSize = GetChoosenSize();
-
- FW_CRect frameRect = GetBounds(ev);
- frameRect.Place(FW_kZeroPoint);
-
- if (choosenSize == cFitToFrame)
- {
- newUsedRect = frameRect;
- }
- else
- {
- fBitmapPart->GetBitmap(ev)->GetBitmapBounds(newUsedRect); // return in 72 dpi
-
- if (choosenSize == cHalfSize)
- {
- newUsedRect.right = newUsedRect.right.DividedByInt(2);
- newUsedRect.bottom = newUsedRect.bottom.DividedByInt(2);
- }
- else if (choosenSize == cDoubleSize)
- {
- newUsedRect.right = newUsedRect.right.MultipliedByInt(2);
- newUsedRect.bottom = newUsedRect.bottom.MultipliedByInt(2);
- }
-
- newUsedRect.PlaceInCenter(frameRect);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CBitmapFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- if (fSelection->IsMouseInDraggableItem(ev, this, theMouseEvent, FALSE))
- {
- if (!Drag(ev, theMouseEvent))
- fSelection->CloseSelection(ev);
- }
- else
- {
- fSelection->CloseSelection(ev);
-
- FW_CRect usedRect;
- CalcUsedRect(ev, usedRect);
-
- FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, theMouseEvent.GetFacet(ev)->GetFrame(ev));
- frame->GetContentView(ev)->FrameToViewContent(ev, where);
-
- if (usedRect.Contains(where))
- {
- // ----- ... and start a track -----
- CRectRubberBand rubberBand(ev, this, theMouseEvent.GetFacet(ev), usedRect, GetZoomRatio(ev));
-
- if (rubberBand.Track(ev, theMouseEvent))
- {
- FW_CRect rect;
- rubberBand.GetRect(rect);
-
- // ----- Apply the zoom ratio ----
- fSelection->SetSelectRect(GetZoomRatio(ev), usedRect, rect);
- fSelection->DrawAnts(ev, this);
- }
- }
- else
- FW_Beep();
- }
-
- return TRUE;
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::CanAcceptDrop
- //----------------------------------------------------------------------------------------
-
- ODDragResult CBitmapFrame::CanAcceptDrop(Environment* ev, ODDragItemIterator* dragInfo)
- {
- ODDragResult result = FW_CFrame::CanAcceptDrop(ev, dragInfo);
-
- // ----- Test for PICT also -----
- if (!result)
- {
- for (ODStorageUnit *dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev))
- if (dragSU->Exists(ev, kODPropContents, FW_CPart::gMacPICTDataType, 0)) // 'PICT' in Scrap
- return TRUE;
- else if (dragSU->Exists(ev, kODPropContents, FW_CPart::gMacPICTFileType, 0)) // PICT file
- return TRUE;
- }
-
- return result;
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::CreateSubviews
- //----------------------------------------------------------------------------------------
-
- void CBitmapFrame::CreateSubviews(Environment* ev)
- {
- if (IsRoot(ev))
- {
- FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
-
- FW_CRect frameRect = this->GetBounds(ev);
- frameRect.bottom -= sbSize.y;
- frameRect.right -= sbSize.x;
-
- // ----- Create the GrowBox gadget
- fGrowBox = new FW_CGrowBox(ev, this, 0, frameRect[FW_kBotRight]);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::AdjustSubviews
- //----------------------------------------------------------------------------------------
-
- void CBitmapFrame::AdjustSubviews(Environment* ev)
- {
- if (IsRoot(ev))
- {
- FW_ASSERT(fGrowBox);
-
- FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
-
- FW_CRect frameRect = GetBounds(ev);
- frameRect.bottom -= sbSize.y;
- frameRect.right -= sbSize.x;
-
- fGrowBox->Invalidate(ev); // Invalidate old position
- fGrowBox->SetLocation(ev, frameRect[FW_kBotRight]);
- fGrowBox->Invalidate(ev); // Invalidate new position
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::ExternalizeFrame
- //----------------------------------------------------------------------------------------
-
- void CBitmapFrame::ExternalizeFrame(Environment* ev, ODStorageUnitView* storageUnitView)
- {
- FW_CFrame::ExternalizeFrame(ev, storageUnitView);
-
- FW_CStorageUnitSink sink(storageUnitView);
- FW_CWritableStream stream(&sink);
- stream << fChoosenSize;
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapFrame::InternalizeFrame
- //----------------------------------------------------------------------------------------
-
- void CBitmapFrame::InternalizeFrame(Environment* ev, ODStorageUnitView* storageUnitView)
- {
- FW_CFrame::InternalizeFrame(ev, storageUnitView);
-
- FW_CStorageUnitSink sink(storageUnitView);
- FW_CReadableStream stream(&sink);
- stream >> fChoosenSize;
- }
-
-